<div id="pageInfo" data-title="发票管理"></div>
<section id="address_list" class="address_list">
	<ul>
		{foreach:items=Api::run("getInvoiceListByUserId")}
		<li>
			<header class="address_list_header">
				{$item['company_name']}【{echo:CountSum::invoiceTypeText($item['type'])}】
			</header>
			<section class="address_list_section">
				{$item['taxcode']}<br/>
				{$item['address']} {$item['telphone']}<br/>
				{$item['bankname']} {$item['bankno']}
			</section>
			<footer class="address_list_footer">
				<span class="address_btn" onclick='edit({$item['id']})'>修改</span>
				<span class="address_btn" onclick="delModel({link:'{url:/ucenter/invoice_del/id/$item['id']}'});">删除</span>
			</footer>
		</li>
		{/foreach}
	</ul>

    {if:!$items}
    <section class="no_tip">暂无记录</section>
    {/if}
</section>
<footer id="viewport_bottom">
    {if:$items}
	<div class="address_edit_btn" id="address_edit_btn">编辑</div>
	{/if}

	<div class="btn_bottom">
		<input type="button" value="添加新发票" class="btn_submit" onclick="edit();" />
	</div>
</footer>
<script>
$(function(){
	// 内页隐藏页底导航
	hideNav();
	// 打开关闭编辑模式
	var btn = $("#address_edit_btn"),
		list = $("#address_list").find('li');
	btn.on('click',function(){
		var t = $(this),
			v = t.data('v');
		if(v==1){
			t.html("编辑").data('v', '0');
			list.children('footer').hide();
		}else{
			t.html("取消").data('v', '1');
			list.children('footer').css('display','table');
		}
	});
});

function edit(taxId)
{
	art.dialog.open(creatUrl("block/invoice/id/"+taxId),
	{
		"id":"taxWindow",
		"title":"发票编辑",
		"ok":function(iframeWin, topWin){
			var formObject = iframeWin.document.forms[0];
			if(formObject.onsubmit() === false)
			{
				alert("请正确填写各项信息");
				return false;
			}
			$.getJSON(formObject.action,$(formObject).serialize(),function(content){
				if(content.result == false)
				{
					alert(content.msg);
					return;
				}
				window.location.reload();
			});
			return false;
		},
		"okVal":"提交",
		"cancel":true,
		"cancelVal":"取消",
	});
}
</script>
